home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <string.h>
-
- #include "lint.h"
- #include "interpret.h"
- #include "object.h"
- #include "exec.h"
- #include "config.h"
- #include "rc.h"
-
- #ifdef mac
- #include "mac.h"
- #endif
-
- static struct function *simul_efunp = 0;
- static int num_simul_efun;
-
- /* Don't release this pointer ever. It is used elsewhere. */
- static char *simul_efun_file_name;
-
- extern void start_new_file PROT((FILE *, int));
- extern void end_new_file PROT((void));
- extern int give_uid_to_object PROT((struct object *));
-
- /*
- * If there is a simul_efun file, then take care of it and extract all
- * information we need.
- */
- void get_simul_efun(svp)
- struct svalue *svp;
- {
- struct object *ob;
- struct function *funp;
- int i;
-
- FILE *f;
- extern struct program *prog;
- extern char *current_file;
- extern int total_lines;
- extern int num_parse_error;
- extern char *inherit_file;
- char tmpname[128];
-
- simul_efun_file_name = make_shared_string(SIMUL_EFUN);
-
- strcpy(tmpname, SIMUL_EFUN);
- strcat(tmpname, ".c");
- f = fopen(tmpname, "r");
- if (f == 0) {
- fprintf(stderr, "%s not found.\n", tmpname);
- LPExit(1);
- }
- start_new_file(f,0);
- current_file = string_copy(tmpname); /* This one is freed below */
- compile_file();
- end_new_file();
- total_lines = 0;
- (void)fclose(f);
- xfree(current_file);
- current_file = 0;
-
- if (inherit_file || num_parse_error > 0 || prog == 0) {
- fprintf(stderr, "Error in %s.\n", tmpname);
- LPExit(1);
- }
-
- num_simul_efun = prog->num_functions;
- fprintf(stderr,"%s loaded: %d functions\n", SIMUL_EFUN,
- prog->num_functions);
- if (num_simul_efun == 0)
- return;
- funp = prog->functions;
- simul_efunp = (struct function *)
- xalloc(sizeof (struct function) * num_simul_efun);
- for (i=0; i < prog->num_functions; i++) {
- simul_efunp[i].name = make_shared_string(funp[i].name);
- simul_efunp[i].flags = funp[i].flags;
- simul_efunp[i].num_arg = funp[i].num_arg;
- simul_efunp[i].type = funp[i].type & TYPE_MOD_MASK;
- }
-
- ob = get_empty_object(prog->num_variables);
-
- ob->name = string_copy(SIMUL_EFUN);
- ob->prog = prog;
- ob->next_all = obj_list;
- obj_list = ob;
- enter_object_hash(ob); /* add name to fast object lookup table */
- current_object = 0;
- give_uid_to_object(ob);
- }
-
- /*
- * Test if 'name' is a simul_efun. The string pointer MUST be a pointer to
- * a shared string.
- */
- struct function *find_simul_efun(name)
- char *name;
- {
- int i;
- for (i=0; i < num_simul_efun; i++) {
- if (name == simul_efunp[i].name)
- return &simul_efunp[i];
- }
- return 0;
- }
-
- char *query_simul_efun_file_name() {
- #ifdef DEBUG
- if (simul_efunp == 0)
- fatal("query_simlu_efun_file_name called when non exists!\n");
- #endif
- return simul_efun_file_name;
- }
-